﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;

using HtmlReader;

namespace HtmlReaderConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            string source;

            // load XHTML test source
            string path = Path.Combine(Directory.GetCurrentDirectory(), "Page.xhtml");
            using (StreamReader sr = new StreamReader(path))
            {
                source = sr.ReadToEnd();
            }

            // load real HTML page
            source = new WebClient().DownloadString("http://international-beat.com/");


            // read link tags
            foreach (var tag in new HtmlReader<Tags.A>().Read(source).Distinct())
            {
                Console.WriteLine("Link {0}\t - {1} [{2}]",
                    string.IsNullOrEmpty(tag.Url) ? "<empty>" : tag.Url, tag.Text, tag.Title);
            }

            // read images tags
            foreach (var tag in new HtmlReader<Tags.Img>().Read(source).Distinct())
            {
                Console.WriteLine("Image {0}\t - {1}", 
                    string.IsNullOrEmpty(tag.Src) ? "<empty>" : tag.Src, tag.Alt);
            }

            var body = new HtmlReader<Tags.Body>().Read(source).First().Content;
            Console.WriteLine("Body \t\t - {0}", body);

            Console.ReadKey();
        }
    }
}
